// Package utils validator 自定义校验函数 https://gin-gonic.com/docs/examples/custom-validators/
package utils

import (
	"github.com/go-playground/validator/v10"
	"regexp"
)

// ValidatePhone 校验手机号
func ValidatePhone(fl validator.FieldLevel) bool {
	phone := fl.Field().String()
	ok, _ := regexp.MatchString(`^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$`, phone)
	if !ok {
		return false
	}
	return true
}

// ValidateEmail 校验邮箱
func ValidateEmail(fl validator.FieldLevel) bool {
	email := fl.Field().String()
	ok, _ := regexp.MatchString(`^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$`, email)
	if !ok {
		return false
	}
	return true
}
